#include <iostream>
#include <fstream>
#include <string>  
#include <DragonBonesHeaders.h>

using namespace std;
using namespace dragonBones;

int main() {
    // 读取JSON文件
    string jsonData = "";
    ifstream ifs("AnimationBaseTest.json");  
    if (ifs) {
        string line;
        while (getline(ifs, line)) {
            jsonData += line + "\n";
        }
        ifs.close();
    }
    else {
        cerr << "Error: Cannot open file test.json" << endl;  
        return 1;  
    }
  
    // 解析DragonBones数据
    JSONDataParser jsdb;
    DragonBonesData* data = jsdb.parseDragonBonesData(jsonData.c_str());  
    if (data == nullptr) {
        cerr << "Error: Cannot parse JSON data" << endl;  
        return 1;
    }
    
    cout << "autoSearch = " << data->autoSearch << endl;
    cout << "frameRate = " << data->frameRate << endl;
    cout << "name = " << data->name << endl;
    cout << "armatures" << endl;
    for (std::map<std::string, ArmatureData*>::iterator it = data->armatures.begin(); it!= data->armatures.end(); it++ ) {

        cout << "string armatures.name = " << it->first << endl;
        cout << "armatures.name = " << it->second->name << endl;
       
        std::map<std::string, BoneData*> bones =  it->second->bones;
        for(map<std::string, BoneData*>::iterator it_bones = bones.begin(); it_bones!=bones.end();it_bones++)
        {
             cout << "bones:" << "it_bones" << endl;
             cout << "it_bones->second->weight = " << it_bones->second->weight << endl;
             cout << "it_bones->second->length = " << it_bones->second->length << endl;
             cout << "it_bones->second->name = " << it_bones->second->name << endl;
        }

        std::map<std::string, SlotData*> slots = it->second->slots;
        for(map<std::string, SlotData*>::iterator it_slots = slots.begin(); it_slots!=slots.end(); it_slots++)
        {
            cout << "slots:" << "it_slots" << endl;
            cout << "it_slots->second->name" << it_slots->second->name << endl;
            cout << "it_slots->second->zOrder" << it_slots->second->zOrder << endl;
            cout << "it_slots->second->displayIndex" << it_slots->second->displayIndex << endl;
        }
    }
  
    // 释放内存  
    delete data;  
    return 0;  
}